<?php
/**
 * 程序初始化文件
 */
define('BASEDIR', dirname(__FILE__) . '/'); 
 
error_reporting(E_ALL);
include BASEDIR."common/error.php";
set_error_handler('error');

@session_start();
//设置输出
header("Content-Type:text/html;charset=utf-8");
//设置时区
date_default_timezone_set('Asia/Shanghai');
//加载基本配置
require_once (BASEDIR . '/conf/system.php');
//统计页面用时\数据库查询次数
global $start_mt,$db_query_count;
$start_mt = microtime(true); $db_query_count = 0;
// Autoloading自动加载类
function __autoload($class) {
	$path = strtolower(str_replace('_', '/', $class));
	if (file_exists(BASEDIR . $path . '.php')) {
		require (BASEDIR . $path . '.php');
	}elseif(file_exists(BASEDIR . 'common/' . $path . '.php')){
		require (BASEDIR . 'common/' . $path . '.php');
	}elseif(file_exists(BASEDIR . 'common/' . $class . '.php')){
		require (BASEDIR . 'common/' . $class . '.php');
	}
}

//获取参数,暂只用GET参数
//接收CA参数
//$_m = isset($_GET['m']) && $_GET['m'] != '' ? $_GET['m'] : 'index';	//指向module
$_c = isset($_GET['c']) && $_GET['c'] != '' ? $_GET['c'] : 'index';	//指向controller
$_a = isset($_GET['a']) && $_GET['a'] != '' ? $_GET['a'] : 'index';	//指向action
$cname = 'Controller_' .  ucfirst($_c);

$action = 'action_' . $_a;
if(class_exists($cname)){
	$controller = new $cname;
	if(method_exists($controller, $action)){
		//初始化db类
		$db = new MyDb(DB_HOST,DB_USER,DB_PWD,DB_DB);
		$controller->$action();		
	}else{
		echo("未找到相应的action");
	}
}else{
	echo("未找到相应的class");
}